package dr.common.utils;

import com.submail.config.AppConfig;
import dr.common.ResultModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * SUBMAIL 赛迪  短信工具类
 */
@Slf4j
@Component
public class SubmailSendUtils {

    @Value("${submail.note.signatureName}")
    private  String signatureName;

    @Value("${submail.note.appid}")
    private  String appid;

    @Value("${submail.note.appKey}")
    private String appKey;

    @Value("${submail.note.signType}")
    private String signType;

    private static AppConfig configT;

    public ResultModel sendNote(String phone, String content){
        if(configT==null){
            configT = new AppConfig();
            configT.setAppId(appid);
            configT.setAppKey(appKey);
            configT.setSignType(signType);
        }
        String finalContent = signatureName + content;
        SubmailMessageSend submail = new SubmailMessageSend(configT);
        submail.addTo(phone);
        submail.addContent(finalContent);
        String sendResult = null;

        try {
            //发送短信
            sendResult = submail.send();
        }catch (Exception e){
            log.error("短信发送失败---：电话：{} ----:内容：{}---:发送结果：{}", phone, finalContent, e.getLocalizedMessage());
        }
        return ResultModel.ok();
    }
}
